package com.chinanet.oracle.repository;

import com.chinanet.oracle.entry.OModel;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;

public interface OModelRepository extends PagingAndSortingRepository<OModel,BigDecimal>{

    @Query(value = "select a.* from MODEL a WHERE  a.MTYPE = '0' AND (a.DELMARK != 'N' OR a.DELMARK IS NULL) ORDER BY TIME DESC", nativeQuery = true)
    Iterable<OModel> findAll();

    @Query(value = "select * from MODEL WHERE MTYPE =:aim AND (DELMARK != 'N' OR DELMARK IS NULL) order by time desc", nativeQuery = true)
    Iterable<OModel> findHistory(@Param("aim") BigDecimal aim);

    @Query(value = "select * from MODEL where PID = ? AND (DELMARK != 'N' OR DELMARK IS NULL)", nativeQuery = true)
    OModel findById(@Param("PID") int pid);

    @Query(value = "select * from model where belong = : AND MTYPE = '0' AND (DELMARK != 'N' OR DELMARK IS NULL)", nativeQuery = true)
    OModel findByKind(@Param("PID") int pid);
}